<?php
namespace Admin\Controller;
use Think\Controller;
class OtherController extends AdminController {
    public function index(){
        if(IS_POST){
            $data = I('post.');
            $data['c_time']=$data['u_time'] = time();
            $res = M('index')->data($data)->add();
            if($res){
                $this->success('设置成功',U('index'));
            }else{
                $this->error('设置失败');
            }
        }else{
            $one = M('index')->order('u_time desc')->find();
            $this->assign('title','首页封面设置');
            $this->assign('one',$one);
            $this->display();
        }
    }

    public function upload_img($type=0)
    {
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize = 2 * 1024 * 1024 ;// 设置附件上传大小 2m
        $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath = './Uploads/'; // 设置附件上传根目录
        // $upload->savePath = 'Goods/'; // 设置附件上传（子）目录
        $upload->subName = array('date','Y/m/d');
        // 上传文件
        $info = $upload->uploadOne($_FILES['file']);
//        dump($info);
//        exit;
        if(!$info) { // 上传错误提示错误信息
            $this->ajaxReturn(array("error"=>$upload->getError()));

        }else{ // 上传成功
            $pic_url = 'Uploads/'.$info['savepath'].$info['savename'];
            $image = new \Think\Image();
            $img = $image->open($pic_url);
            $img->save($pic_url);
//                $img->thumb(555, 350,3)->water($waterImgUrl,$water['mark_pos'],$water['alpha'])->save($pic_url);

            // $img->thumb(400, 800,3)->water($water['mark_img'])->save($thumb);
            // $img1->water($water['mark_img'])->save($pic_url);
            $this->ajaxReturn(array('error'=>'0','pic'=>__ROOT__.'/'.$pic_url,'name'=>$info['savename']));
        }
    }
}
?>